package com.zenchn.dynamic;

import static com.zenchn.dynamic.TSysAreasDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.zenchn.model.TSysAreas;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface TSysAreasDynamicMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    BasicColumn[] selectList = BasicColumn.columnList(code, parentCode, shortCode, parentShortCode, name, longitude, latitude, grade, province, city, district, town, village, fullName, category, isEnable, memo);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<TSysAreas> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<TSysAreas> multipleInsertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("TSysAreasResult")
    Optional<TSysAreas> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="TSysAreasResult", value = {
        @Result(column="code", property="code", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="parent_code", property="parentCode", jdbcType=JdbcType.CHAR),
        @Result(column="short_code", property="shortCode", jdbcType=JdbcType.CHAR),
        @Result(column="parent_short_code", property="parentShortCode", jdbcType=JdbcType.CHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="longitude", property="longitude", jdbcType=JdbcType.DECIMAL),
        @Result(column="latitude", property="latitude", jdbcType=JdbcType.DECIMAL),
        @Result(column="grade", property="grade", jdbcType=JdbcType.CHAR),
        @Result(column="province", property="province", jdbcType=JdbcType.VARCHAR),
        @Result(column="city", property="city", jdbcType=JdbcType.VARCHAR),
        @Result(column="district", property="district", jdbcType=JdbcType.VARCHAR),
        @Result(column="town", property="town", jdbcType=JdbcType.VARCHAR),
        @Result(column="village", property="village", jdbcType=JdbcType.VARCHAR),
        @Result(column="full_name", property="fullName", jdbcType=JdbcType.VARCHAR),
        @Result(column="category", property="category", jdbcType=JdbcType.VARCHAR),
        @Result(column="is_enable", property="isEnable", jdbcType=JdbcType.BIT),
        @Result(column="memo", property="memo", jdbcType=JdbcType.VARCHAR)
    })
    List<TSysAreas> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, TSysAreas, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, TSysAreas, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default int deleteByPrimaryKey(String code_) {
        return delete(c -> 
            c.where(code, isEqualTo(code_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default int insert(TSysAreas record) {
        return MyBatis3Utils.insert(this::insert, record, TSysAreas, c ->
            c.map(code).toProperty("code")
            .map(parentCode).toProperty("parentCode")
            .map(shortCode).toProperty("shortCode")
            .map(parentShortCode).toProperty("parentShortCode")
            .map(name).toProperty("name")
            .map(longitude).toProperty("longitude")
            .map(latitude).toProperty("latitude")
            .map(grade).toProperty("grade")
            .map(province).toProperty("province")
            .map(city).toProperty("city")
            .map(district).toProperty("district")
            .map(town).toProperty("town")
            .map(village).toProperty("village")
            .map(fullName).toProperty("fullName")
            .map(category).toProperty("category")
            .map(isEnable).toProperty("isEnable")
            .map(memo).toProperty("memo")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default int insertMultiple(Collection<TSysAreas> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, TSysAreas, c ->
            c.map(code).toProperty("code")
            .map(parentCode).toProperty("parentCode")
            .map(shortCode).toProperty("shortCode")
            .map(parentShortCode).toProperty("parentShortCode")
            .map(name).toProperty("name")
            .map(longitude).toProperty("longitude")
            .map(latitude).toProperty("latitude")
            .map(grade).toProperty("grade")
            .map(province).toProperty("province")
            .map(city).toProperty("city")
            .map(district).toProperty("district")
            .map(town).toProperty("town")
            .map(village).toProperty("village")
            .map(fullName).toProperty("fullName")
            .map(category).toProperty("category")
            .map(isEnable).toProperty("isEnable")
            .map(memo).toProperty("memo")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default int insertSelective(TSysAreas record) {
        return MyBatis3Utils.insert(this::insert, record, TSysAreas, c ->
            c.map(code).toPropertyWhenPresent("code", record::getCode)
            .map(parentCode).toPropertyWhenPresent("parentCode", record::getParentCode)
            .map(shortCode).toPropertyWhenPresent("shortCode", record::getShortCode)
            .map(parentShortCode).toPropertyWhenPresent("parentShortCode", record::getParentShortCode)
            .map(name).toPropertyWhenPresent("name", record::getName)
            .map(longitude).toPropertyWhenPresent("longitude", record::getLongitude)
            .map(latitude).toPropertyWhenPresent("latitude", record::getLatitude)
            .map(grade).toPropertyWhenPresent("grade", record::getGrade)
            .map(province).toPropertyWhenPresent("province", record::getProvince)
            .map(city).toPropertyWhenPresent("city", record::getCity)
            .map(district).toPropertyWhenPresent("district", record::getDistrict)
            .map(town).toPropertyWhenPresent("town", record::getTown)
            .map(village).toPropertyWhenPresent("village", record::getVillage)
            .map(fullName).toPropertyWhenPresent("fullName", record::getFullName)
            .map(category).toPropertyWhenPresent("category", record::getCategory)
            .map(isEnable).toPropertyWhenPresent("isEnable", record::getIsEnable)
            .map(memo).toPropertyWhenPresent("memo", record::getMemo)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default Optional<TSysAreas> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, TSysAreas, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default List<TSysAreas> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, TSysAreas, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default List<TSysAreas> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, TSysAreas, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default Optional<TSysAreas> selectByPrimaryKey(String code_) {
        return selectOne(c ->
            c.where(code, isEqualTo(code_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, TSysAreas, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    static UpdateDSL<UpdateModel> updateAllColumns(TSysAreas record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(code).equalTo(record::getCode)
                .set(parentCode).equalTo(record::getParentCode)
                .set(shortCode).equalTo(record::getShortCode)
                .set(parentShortCode).equalTo(record::getParentShortCode)
                .set(name).equalTo(record::getName)
                .set(longitude).equalTo(record::getLongitude)
                .set(latitude).equalTo(record::getLatitude)
                .set(grade).equalTo(record::getGrade)
                .set(province).equalTo(record::getProvince)
                .set(city).equalTo(record::getCity)
                .set(district).equalTo(record::getDistrict)
                .set(town).equalTo(record::getTown)
                .set(village).equalTo(record::getVillage)
                .set(fullName).equalTo(record::getFullName)
                .set(category).equalTo(record::getCategory)
                .set(isEnable).equalTo(record::getIsEnable)
                .set(memo).equalTo(record::getMemo);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(TSysAreas record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(code).equalToWhenPresent(record::getCode)
                .set(parentCode).equalToWhenPresent(record::getParentCode)
                .set(shortCode).equalToWhenPresent(record::getShortCode)
                .set(parentShortCode).equalToWhenPresent(record::getParentShortCode)
                .set(name).equalToWhenPresent(record::getName)
                .set(longitude).equalToWhenPresent(record::getLongitude)
                .set(latitude).equalToWhenPresent(record::getLatitude)
                .set(grade).equalToWhenPresent(record::getGrade)
                .set(province).equalToWhenPresent(record::getProvince)
                .set(city).equalToWhenPresent(record::getCity)
                .set(district).equalToWhenPresent(record::getDistrict)
                .set(town).equalToWhenPresent(record::getTown)
                .set(village).equalToWhenPresent(record::getVillage)
                .set(fullName).equalToWhenPresent(record::getFullName)
                .set(category).equalToWhenPresent(record::getCategory)
                .set(isEnable).equalToWhenPresent(record::getIsEnable)
                .set(memo).equalToWhenPresent(record::getMemo);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default int updateByPrimaryKey(TSysAreas record) {
        return update(c ->
            c.set(parentCode).equalTo(record::getParentCode)
            .set(shortCode).equalTo(record::getShortCode)
            .set(parentShortCode).equalTo(record::getParentShortCode)
            .set(name).equalTo(record::getName)
            .set(longitude).equalTo(record::getLongitude)
            .set(latitude).equalTo(record::getLatitude)
            .set(grade).equalTo(record::getGrade)
            .set(province).equalTo(record::getProvince)
            .set(city).equalTo(record::getCity)
            .set(district).equalTo(record::getDistrict)
            .set(town).equalTo(record::getTown)
            .set(village).equalTo(record::getVillage)
            .set(fullName).equalTo(record::getFullName)
            .set(category).equalTo(record::getCategory)
            .set(isEnable).equalTo(record::getIsEnable)
            .set(memo).equalTo(record::getMemo)
            .where(code, isEqualTo(record::getCode))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: t_sys_areas")
    default int updateByPrimaryKeySelective(TSysAreas record) {
        return update(c ->
            c.set(parentCode).equalToWhenPresent(record::getParentCode)
            .set(shortCode).equalToWhenPresent(record::getShortCode)
            .set(parentShortCode).equalToWhenPresent(record::getParentShortCode)
            .set(name).equalToWhenPresent(record::getName)
            .set(longitude).equalToWhenPresent(record::getLongitude)
            .set(latitude).equalToWhenPresent(record::getLatitude)
            .set(grade).equalToWhenPresent(record::getGrade)
            .set(province).equalToWhenPresent(record::getProvince)
            .set(city).equalToWhenPresent(record::getCity)
            .set(district).equalToWhenPresent(record::getDistrict)
            .set(town).equalToWhenPresent(record::getTown)
            .set(village).equalToWhenPresent(record::getVillage)
            .set(fullName).equalToWhenPresent(record::getFullName)
            .set(category).equalToWhenPresent(record::getCategory)
            .set(isEnable).equalToWhenPresent(record::getIsEnable)
            .set(memo).equalToWhenPresent(record::getMemo)
            .where(code, isEqualTo(record::getCode))
        );
    }
}